package com.css.ztb.filter;

import com.css.ztb.common.ShiroConstants;
import org.springframework.beans.factory.annotation.Value;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 验证码过滤器
 * 
 * @author ruoyi
 */
@WebFilter(filterName = "captchaValidateFilter", urlPatterns = "/*")
public class CaptchaValidateFilter implements Filter
{
    // 验证码开关
    @Value("${shiro.user.captchaEnabled}")
    private boolean captchaEnabled;

    // 验证码类型
    @Value("${shiro.user.captchaType}")
    private String captchaType;

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setAttribute(ShiroConstants.CURRENT_ENABLED, captchaEnabled);
        request.setAttribute(ShiroConstants.CURRENT_TYPE, captchaType);
        chain.doFilter(request, response);
    }
}
